package com.dhcc.producter.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.ExchangeBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitFanoutExchangeConfiguration {

	// 交换机
	@Bean
	public Exchange fanoutExchange() {
		Exchange exchange = ExchangeBuilder.fanoutExchange("fanout-exchange").durable(true).build();
		return exchange;
	}
	
	// 队列
	@Bean
	public Queue fanoutQueue01() {
		Queue queue = QueueBuilder.durable("fanout-queue-01").build();
		return queue;
	}
	
	@Bean
	public Queue fanoutQueue02() {
		Queue queue = QueueBuilder.durable("fanout-queue-02").build();
		return queue;
	}
	
	// 关系
	@Bean
	public Binding fanoutExchangeQueue01() {
		Binding binding01 = BindingBuilder.bind(fanoutQueue01()).to(fanoutExchange()).with("").noargs();
		return binding01;
	}
	
	@Bean
	public Binding fanoutExchangeQueue02() {
		Binding binding02 = BindingBuilder.bind(fanoutQueue02()).to(fanoutExchange()).with("").noargs();
		return binding02;
	}
}
